﻿using Azukit.Messaging;
using Azukit.WPF.ViewModel;

namespace Hibiku.ViewModels
{
    public class ReplyViewModel : ViewAwareViewModelBase, ITransceiverOwner
    {
        private TweetViewModel _tweet;
        public TweetViewModel Tweet
        {
            get
            {
                return _tweet;
            }
            set
            {
                _tweet = value;

                DisplayName = string.Format("Reply to tweet by {0}", value.Tweet.User.ScreenName);

                FirePropertyChanged(() => Tweet);


                Transceiver.Send(value.Tweet);
            }
        }

        public ReplyViewModel(ITransceiver transceiver)
        {
            _transceiver = transceiver;

            DisplayName = "Reply to";

            Transceiver.Listen<TweetComposerViewModel.TweetSentMessage>(HandleTweetSentMessage);
        }

        private void HandleTweetSentMessage(TweetComposerViewModel.TweetSentMessage message)
        {
            CloseView();
        }

        #region ITransceiverOwner Members

        private readonly ITransceiver _transceiver;
        public ITransceiver Transceiver
        {
            get { return _transceiver; }
        }

        #endregion
    }
}
